package paixu;

import org.junit.Test;

public class Sort {


    //利用冒泡排序
//    @org.junit.Test
    public void demo1() {
        int[] numbers = {4, 7, 1, 6, 2, 3, 5};
        int y;
        for (int i = 0; i < numbers.length - 1; i++) {
            for (int j = 0; j < numbers.length - 1 - i; j++) {
                if (numbers[j] > numbers[j + 1]) {
                    y = numbers[j];
                    numbers[j] = numbers[j + 1];
                    numbers[j + 1] = y;
                }
            }
        }
        System.out.print("该数组从小到大的顺序为");
        for (int i = 0; i < numbers.length; i++) {
            System.out.print(numbers[i]);
        }
    }

    //利用选择排序
    @Test
    public void demo2(){
        int[] numbers = {4, 7, 1, 6, 3, 2, 5};
        //假设size是未定义数组中的最小值
        int size;
        int temp;
        for (int i = 0; i <numbers.length-1 ; i++) {
            size=i;
            for (int j=1+i; j < numbers.length; j++) {
                if (numbers[size] > numbers[j]) {
                    temp=numbers[size];
                    numbers[size]=numbers[j];
                    numbers[j]=temp;
                }
            }
        }
        for (int i = 0; i < numbers.length; i++) {
            System.out.println(numbers[i]);

        }
    }

}